import { defineConfig } from 'vite'
import path from 'path'
import { viteExternalsPlugin } from 'vite-plugin-externals'

const resolve = (url) => path.resolve(__dirname, url)

export default defineConfig({
    plugins: process.env.NODE_ENV === 'production'? [
        viteExternalsPlugin({
            three: 'THREE'})]:[],
    css: {
        modules: {
            // css: true,
            // scss: true, 
            generateScopedName: '[name]__[local]___[hash:base64:5]',
        },
        preprocessorOptions: {
            less: {
                javascriptEnabled: true,
            }      
        }
    },
    build: {
        lib: {
            entry: resolve('src/vr_hall/index.js'),
            name: 'VRHall',
            fileName: (format) => `lib/vr_hall.${format}.js`
        }
    },
    resolve: {
        alias: {
            '@': path.resolve(__dirname, 'src')
        }
    },
    base: './',
    server: {
        host: '0.0.0.0',
        port: 3000,
        // proxy: {
        //     '/api': {
        //         target: 'http://localhost:3000', // 代理目标地址
        //         changeOrigin: true, // 是否改变源地址
        //         rewrite: (path) => path.replace(/^\/api/, '') // 重写请求路径
        //     }
        // }
    }
})